package fun.tan90.device.source.http.plugin;

import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;
import org.noear.solon.core.event.EventBus;
import org.noear.solon.core.event.EventListener;

@Slf4j
public class SourceHttpPlugin implements Plugin {

    AppContext context;

    @Override
    public void start(AppContext context) {
        log.info("SourceHttpPlugin start");
        this.context = context;
        //添加自己的配置文件
        context.cfg().loadAdd("source-http.yml");
        //扫描自己的bean
        context.beanScan(SourceHttpPlugin.class);
    }

    @Override
    public void stop() {
        log.info("SourceMqttPlugin stop");
        //移除事件订阅
        context.beanForeach(bw -> {
            if (bw.raw() instanceof EventListener) {
                EventBus.unsubscribe(bw.raw());
            } else if (bw.raw() instanceof Vertx vertx) {
                vertx.close();
            }
        });
    }
}